﻿using OnlineMealOrdering.Common;
using OnlineMealOrdering.Domain.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;

namespace OnlineMealOrdering.Domain
{
    public class StoreOnlineEntity : AuditableEntity
    {
        public string Name { get; set; }

        public string PinYin { get; set; }

        public string Description { get; set; }

        public string Tel { get; set; }

        public string Phone { get; set; }

        public string QQ { get; set; }

        public string WeiBo { get; set; }

        public string Contact { get; set; }

        //[DataType(System.ComponentModel.DataAnnotations.DataType.Time)]
        public DateTime BeginBusinessTime { get; set; }

        //[DataType(System.ComponentModel.DataAnnotations.DataType.Time)]
        public DateTime EndBusinessTime { get; set; }

        //经度
        public decimal Longitude { get; set; }
        //维度
        public decimal Latitude { get; set; }

        //商家的送餐范围
        public virtual ICollection<AreaCoordinateEntity> AreaCoordinate { get; set; }

        //电话订餐还是网上订单
        public EnunStoreType Type { get; set; }

        //起步价
        public decimal InitiatePrice { get; set; }

        [DataType(System.ComponentModel.DataAnnotations.DataType.MultilineText)]
        public string Address { get; set; }

        public int SortNo { get; set; }

        public EnumStoreStatus Status { get; set; }

        public virtual ImageEntity LogoImage { get; set; }

        public virtual ICollection<ImageEntity> Images { get; set; }

        //推荐或者热销标志
        public virtual ICollection<MarkEntity> Marks { get; set; }
        //公告 和描述 用类型分开
        public virtual ICollection<NoticeEntity> Notices { get; set; }

        public virtual ICollection<FoodCatalogEntity> Catalogs { get; set; }

        public virtual ICollection<TagEntity> Tags { get; set; }

        public virtual ICollection<StoreCommentEntity> Comment { get; set; }

        public virtual ICollection<FoodEntity> Foods { get; set; }

        public static StoreOnlineEntity Create(string name, string description, string tel, string phone, string qq, string weibo, int sortNo, string note,
            string contact, DateTime beginBusinessTime, DateTime endBusinessTime, decimal longitude, decimal latitude, EnunStoreType type, decimal initiatePrice, string address, ICollection<TagEntity> tag, ICollection<ImageEntity> img, ICollection<FoodCatalogEntity> catalogs)
        {
            var entity = new StoreOnlineEntity();
            entity.Catalogs = catalogs;
            entity.Images = img;
            entity.Tags = tag;
            entity.Name = name;
            entity.PinYin = GetCharSpellCodeHelp.GetChineseSpell(name).ToLower();
            entity.Description = description;
            entity.Tel = tel;
            entity.Phone = phone;
            entity.QQ = qq;
            entity.SortNo = sortNo;
            entity.WeiBo = weibo;
            entity.Contact = contact;
            entity.BeginBusinessTime = beginBusinessTime;
            entity.EndBusinessTime = endBusinessTime;
            entity.Longitude = longitude;
            entity.Latitude = latitude;
            entity.Type = type;
            entity.InitiatePrice = initiatePrice;
            entity.Address = address;
            entity.Status = EnumStoreStatus.Create;
            entity.Notices = new List<NoticeEntity>();
            entity.Notices.Add(NoticeEntity.Create(WebNoteType.OnlineNote, "", note));

            return entity;
        }

        public static StoreOnlineEntity GetStoreOnline(int id)
        {
            return DomainContext.Current.EntitySet<StoreOnlineEntity>().Single(a => a.Id == id);
        }
    }
}
